package gui.customizer.panes.logs;

import java.awt.Font;
import java.util.Collection;

import javax.swing.JPanel;
import javax.swing.JTextArea;

import net.miginfocom.swing.MigLayout;
import javax.swing.JScrollPane;
import javax.swing.text.DefaultCaret;

public class IptablesLogsArea extends JPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = -1859175597419385659L;
	private JTextArea txtrLogs;

	public IptablesLogsArea() {
		setLayout(new MigLayout("", "[grow]", "[grow]"));
		
		txtrLogs = new JTextArea();
		txtrLogs.setEditable(false);
		DefaultCaret caret = (DefaultCaret)txtrLogs.getCaret();
		caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
		txtrLogs.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
		JScrollPane logsAreaScroller = new JScrollPane(txtrLogs);
		add(logsAreaScroller, "cell 0 0,grow");
	}
	
	public void appendLine(String line) {
		txtrLogs.append(line);
	}
	
	public void appendLines(Collection<String> lines) {
		for (String line : lines) {
			txtrLogs.append(line);
			txtrLogs.append("\n");
		}
	}
	
	public void setLines(Collection<String> lines) {
		txtrLogs.setText("");
		appendLines(lines);
	}

}
